﻿// hm_register.cpp: 实现文件
//

#include "pch.h"
#include "HoManSys1.h"
#include "hm_register.h"
#include "afxdialogex.h"
#include "ADOconnection.h"

// hm_register 对话框
ADOconnection conn;
ADOconnection con6;
IMPLEMENT_DYNAMIC(hm_register, CDialogEx)

hm_register::hm_register(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG1, pParent)
	, m_vusername(_T(""))
	, m_vpassword1(_T(""))
	, m_vpassword2(_T(""))
	

{
#ifndef _WIN32_WCE
	EnableActiveAccessibility();
#endif

}

hm_register::~hm_register()
{
}

void hm_register::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, m_vusername);
	DDX_Text(pDX, IDC_EDIT2, m_vpassword1);
	DDX_Text(pDX, IDC_EDIT3, m_vpassword2);
}


BEGIN_MESSAGE_MAP(hm_register, CDialogEx)
	ON_BN_CLICKED(IDOK, &hm_register::OnBnClickedOk)
	
END_MESSAGE_MAP()


// hm_register 消息处理程序


void hm_register::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	_RecordsetPtr m_ptr;
	_variant_t  vFieldValue;
	CString strField;
	ADOconnection   m_Conn;
	m_Conn.DBConnection();
	UpdateData();      //true: 把控件中的值赋给控件对应的变量  //false：把变量的值在控件中显示
	m_Conn.m_pRs.CreateInstance(__uuidof(Recordset));
	CString strSelect = _T("select * from staff where staffID='" + m_vusername + "'");
	//MessageBox(strSelect);
	m_Conn.m_pRs->Open(_bstr_t(strSelect), m_Conn.m_pCon.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);

	m_ptr = m_Conn.m_pRs;
	if (m_ptr->adoEOF)
	{
		MessageBox(_T("员工不存在！"));
		return;
	}
	else
	{
		if (m_vpassword2 != m_vpassword1)
			{
			MessageBox(_T("密码不一致！"));
			}
		else {
			conn.DBConnection();

			CString str_in = _T("insert into userd values('" + m_vusername + "', '" + m_vpassword2 + "')");
			_variant_t RecordsAffected;
			conn.m_pCon->Execute(_bstr_t(str_in), &RecordsAffected, adCmdText);
		
			MessageBox(_T("注册成功！"));
		}

		}

	
	CDialogEx::OnOK();
}


